/* Source file https://github.com/MrOtherGuy/firefox-csshacks/tree/master/chrome/multi-row_tabs.css made available under Mozilla Public License v. 2.0
See the above repository for updates as well as full license text. */

/* Makes tabs to appear on multiple lines
 * Tab reordering will not work and can't be made to work
 * You can use multi-row_tabs_window_control_patch.css to move window controls to nav-bar
 * You might want to move tabs-new-tab-button outside tabs toolbar for smoother behavior */

/* SETTINGS (you need to create and set these prefs to true in about:config)
 * userchrome.multirowtabs.full-width-tabs.enabled  - make tabs grow horizontally to fill all available space
 * userchrome.multirowtabs.scrollbar-handle.enabled - make scrollbar in tabs box respond to mouse, makes it imposiible to drag window from empty space in tabs box */

:root{
  --multirow-n-rows: 3; /* change maximum number of rows before the rows will start to scroll */
  --multirow-tab-min-width: 100px;
  --multirow-tab-dynamic-width: 1; /* Change to 0 for fixed-width tabs using the above width. */
}

#tabbrowser-tabs[orient="horizontal"]{
  min-height: unset !important;
  padding-inline-start: 0px !important;
  --uc-scrollbutton-display-model: none;
  --uc-scrollbox-display-model: contents;
  flex-wrap: wrap;
  overflow-y: auto;
  overflow-x: hidden;
  max-height: calc((var(--tab-min-height) + 2 * var(--tab-block-margin,0px)) * var(--multirow-n-rows));
  scrollbar-color: currentColor transparent;
  scrollbar-width: thin;
  scrollbar-gutter: stable;
  scroll-snap-type: y mandatory;
}

@-moz-document url(chrome://browser/content/browser.xhtml){
  #scrollbutton-up~spacer,
  #scrollbutton-up,
  #scrollbutton-down{ display: var(--uc-scrollbutton-display-model,initial) }
  
  #pinned-tabs-container[orient="horizontal"],
  #tabbrowser-arrowscrollbox[orient="horizontal"],
  scrollbox[part][orient="horizontal"] > slot,
  scrollbox[part="scrollbox"][orient="horizontal"]{
    display: var(--uc-scrollbox-display-model,initial) !important;
  }
}

.tabbrowser-tab{ scroll-snap-align: start; }

#tabbrowser-tabs .tabbrowser-tab[pinned]{
  position: static !important;
  margin-inline-start: 0px !important;
}

.tabbrowser-tab[fadein]:not([pinned]){
  min-width: var(--multirow-tab-min-width) !important;
  flex-grow: var(--multirow-tab-dynamic-width) !important;
}

.tabbrowser-tab > stack{ width: 100%; height: 100% }

/* remove bottom margin so it doesn't throw off row height computation */
#tabs-newtab-button{ margin-bottom: 0 !important; }

#tabbrowser-tabs[hasadjacentnewtabbutton][overflow] > #tabbrowser-arrowscrollbox > #tabbrowser-arrowscrollbox-periphery > #tabs-newtab-button {
  display: flex !important;
}

#alltabs-button[removable="false"],
:root:not([customizing]) #TabsToolbar #new-tab-button,
#tabbrowser-arrowscrollbox > spacer,
.tabbrowser-tab::after{ display: none !important }

@media -moz-pref("userchrome.multirowtabs.full-width-tabs.enabled"){
  .tabbrowser-tab[fadein]:not([pinned]){ max-width: 100vw !important; }
}
@media -moz-pref( "userchrome.multirowtabs.scrollbar-handle.enabled"){
  #tabbrowser-arrowscrollbox{ -moz-window-dragging: no-drag }
}

/* Make tab groups collapse */
tab-group[collapsed] .tabbrowser-tab[fadein]:not([pinned]){
  min-width: 0 !important;
}
